<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-11-05 10:18:56
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" other
-->
<template>
  <el-drawer
    :title="'售后'"
    v-model="visible"
    :size="'70%'"
    @success="emit('success')"
    destroy-on-close
    @closed="emit('closed')"
  >
    <sc-VxeTable
      ref="xGrid1"
      :gridEvts="gridEvents"
      :tablecode="'purchase_complaint_storage'"
      :params="[
        {
          status_id: { type: 'gt', value: 0 },
        },
      ]"
      :url="api.purchase.order.list"
    >
    </sc-VxeTable>
  </el-drawer>
  <save-dig
    v-if="dialog.save"
    ref="saveDialog"
    @closed="dialog.save = false"
    @success="emit('success')"
  ></save-dig>
</template>

<script setup>
import { ref, nextTick } from "vue";
import saveDig from "./save";
import api from "@/api";
const dialog = ref({
  save: false,
});
const saveDialog = ref();
const visible = ref(false);
const open = function () {
  visible.value = true;
  return this;
};
const close = function () {
  visible.value = false;
};
let handleSuccessFn = null;
const setHandle = function (v) {
  handleSuccessFn = v;
};
const emit = defineEmits(["closed", "success"]);
defineExpose({
  open,
  close,
  setHandle,
});
const edit = function (row) {
  row.red_id = row.id;
  row.relation_code = row.code;
  delete row.id;
  delete row.code;
  row.old_billdate = row.main.billdate;
  row.in_date = row.audited_at;
  dialog.value.save = true;
  nextTick(() => {
    saveDialog.value.setData(row);
    saveDialog.value.open("add").setHandle(handleSuccessFn);
    close();
  });
};
const gridEvents = {
  edit: function ({ button }) {
    edit(button.selectRecords[0]);
  },
  cellDblclick: ({ row }) => {
    edit(row);
  },
};
</script>
